package com.javastudy.autowiredStudy.importStudy;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Import 注解能够导入哪些类型
 * @author mac
 * @date 2021/9/9 10:19 上午
 */
@Import({MyConfA.class,MyBConf.class,MyImportSelectorImpl.class,MyImportBeanDefinitionRegistrarImpl.class})
@Configuration
public class MyConf {
}

/**
 * 普通类
 */
class MyConfA{}

/**
 * 添加了@Configuration注解的类
 */
@Configuration
class MyBConf{}

/**
 * 实现了ImportSelector接口的类
 */
class MyImportSelectorImpl implements ImportSelector{
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        return new String[0];
    }
}

/**
 * 实现了ImportBeanDefinitionRegistrar接口的类
 */
class MyImportBeanDefinitionRegistrarImpl implements ImportBeanDefinitionRegistrar{
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
        ImportBeanDefinitionRegistrar.super.registerBeanDefinitions(importingClassMetadata, registry, importBeanNameGenerator);
    }
}